package com.moxiao.yfjh.module.activity.dal.mysql.productInfo;

import java.util.*;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.moxiao.yfjh.framework.mybatis.core.mapper.BaseMapperX;
import com.moxiao.yfjh.module.activity.dal.dataobject.productInfo.ProductInfoDO;
import org.apache.ibatis.annotations.Mapper;
import com.moxiao.yfjh.module.activity.controller.admin.productInfo.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 相亲商品信息 Mapper
 *
 * @author mx
 */
@Mapper
public interface ProductInfoMapper extends BaseMapperX<ProductInfoDO> {

    default PageResult<ProductInfoDO> selectPage(ProductInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProductInfoDO>()
                .eqIfPresent(ProductInfoDO::getNo, reqVO.getNo())
                .likeIfPresent(ProductInfoDO::getName, reqVO.getName())
                .eqIfPresent(ProductInfoDO::getProductType, reqVO.getProductType())
                .eqIfPresent(ProductInfoDO::getMerchantId, reqVO.getMerchantId())
                .eqIfPresent(ProductInfoDO::getAddress, reqVO.getAddress())
                .eqIfPresent(ProductInfoDO::getSupplyPrice, reqVO.getSupplyPrice())
                .eqIfPresent(ProductInfoDO::getPlatformPrice, reqVO.getPlatformPrice())
                .eqIfPresent(ProductInfoDO::getProductIntroduct, reqVO.getProductIntroduct())
                .eqIfPresent(ProductInfoDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(ProductInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(reqVO.getOrderByPrice() != null && reqVO.getOrderByPrice() == 1,ProductInfoDO::getSupplyPrice)
                .orderByDesc(reqVO.getOrderByPrice() != null && reqVO.getOrderByPrice() == 2,ProductInfoDO::getSupplyPrice));


    }

    default List<ProductInfoDO> selectList(ProductInfoExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ProductInfoDO>()
                .eqIfPresent(ProductInfoDO::getNo, reqVO.getNo())
                .likeIfPresent(ProductInfoDO::getName, reqVO.getName())
                .eqIfPresent(ProductInfoDO::getProductType, reqVO.getProductType())
                .eqIfPresent(ProductInfoDO::getMerchantId, reqVO.getMerchantId())
                .eqIfPresent(ProductInfoDO::getAddress, reqVO.getAddress())
                .eqIfPresent(ProductInfoDO::getSupplyPrice, reqVO.getSupplyPrice())
                .eqIfPresent(ProductInfoDO::getPlatformPrice, reqVO.getPlatformPrice())
                .eqIfPresent(ProductInfoDO::getProductIntroduct, reqVO.getProductIntroduct())
                .eqIfPresent(ProductInfoDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(ProductInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ProductInfoDO::getId));
    }

    @Select("select count(*) num from blind_product_info where no = #{productInfoNo}")
    Integer getProductInfoNo(@Param("productInfoNo") String productInfoNo);
}
